package com.cloudsigns.factorymanager2.project.activity;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.project.utils.ConstantUtil;

/**
 * 编辑产品信息
 * Created by tony on 2017/12/13.
 */

public class EditProductInformationActivity extends Activity implements View.OnClickListener {
    private ImageView img_back;
    private TextView tv_title;
    private RelativeLayout rl_rect_content, rl_circular_content, rl_drawings_content;
    private RadioGroup rg_associated_size;
    private RadioButton rb_rect;
    private TextView btn_upload, btn_remove;
    private EditText edt__product_name, edt__product_quatity;
    private TextView edt__unit;
    private String imgUrl = "";
//    private int shap = ConstantUtil.CIRCULAR;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
        // 沉浸式状态栏
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                    );
            window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN

                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);

        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
        setContentView(R.layout.layout_edit_product_information);

        init();
    }

    private void init() {
        img_back = findViewById(R.id.img_back);
        tv_title = findViewById(R.id.tv_title);
        rl_rect_content = findViewById(R.id.rl_rect_content);
        rl_circular_content = findViewById(R.id.rl_circular_content);
        rl_drawings_content = findViewById(R.id.rl_drawings_content);
        rg_associated_size = findViewById(R.id.rg_associated_size);
        rb_rect = findViewById(R.id.rb_rect);
        btn_upload = findViewById(R.id.btn_upload);
        btn_remove = findViewById(R.id.btn_remove);
        edt__product_name = findViewById(R.id.edt__product_name);
        edt__product_quatity = findViewById(R.id.edt__product_quatity);
        edt__unit = findViewById(R.id.edt__unit);


        tv_title.setText(getResources().getText(R.string.add_product_infomation));
        img_back.setOnClickListener(this);
        btn_upload.setOnClickListener(this);
        btn_remove.setOnClickListener(this);
        rb_rect.setChecked(true);
//        rg_associated_size.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
//            @Override
//            public void onCheckedChanged(RadioGroup radioGroup, @IdRes int id) {
//                if (id == R.id.rb_rect) {
//                    shap = ConstantUtil.RECT;
//                    showShapContent();
//                } else if (id == R.id.rb_circular) {
//                    shap = ConstantUtil.CIRCULAR;
//                    showShapContent();
//                } else if (id == R.id.rb_hateromorphism) {
//                    shap = ConstantUtil.ALIEN;
//                    showShapContent();
//                }
//
//
//            }
//        });
    }

    /**
     * 根据选中的形状，显示不同的内容
     */

    private void showShapContent() {
//        if (shap == ConstantUtil.RECT) {
//            rl_rect_content.setVisibility(View.VISIBLE);
//            rl_circular_content.setVisibility(View.GONE);
//            rl_drawings_content.setVisibility(View.GONE);
//        } else if (shap == ConstantUtil.CIRCULAR) {
//            rl_rect_content.setVisibility(View.GONE);
//            rl_circular_content.setVisibility(View.VISIBLE);
//            rl_drawings_content.setVisibility(View.GONE);
//
//        } else if (shap == ConstantUtil.ALIEN) {
//            rl_rect_content.setVisibility(View.GONE);
//            rl_circular_content.setVisibility(View.GONE);
//            rl_drawings_content.setVisibility(View.VISIBLE);
//
//        }

    }

    /**
     * 上传产品信息
     */
    private void upload() {
//        String productName = edt__product_name.getText().toString().trim();
//        int productQuantity = 0;
//        if (!TextUtils.isEmpty(edt__product_quatity.getText().toString().trim())) {
//            productQuantity = Integer.parseInt(edt__product_quatity.getText().toString().trim());
//        }
//        String unit = edt__unit.getText().toString().trim();
//        String productPicture = "";
//        ShapBean shapBean = null;
//        int shap_type = shap;
//        switch (shap_type) {
//            case ConstantUtil.RECT:
//                shapBean = new RectBean(rectLength, rectHeight, rectThickness, rectLeftSideSize_Up, rectLeftSideSize_Down, rectLeftSideSize_Left, rectLeftSideSize_Right);
//                break;
//            case ConstantUtil.CIRCULAR:
//                shapBean = new CircularBean(circularDiametre, circularThickness, circularLeftSideSize);
//                break;
//            case ConstantUtil.ALIEN:
//                shapBean = new AlienBean(alienDrawings, alienInstruction);
//                break;
//        }
//
//        ProductBean productBean = new ProductBean(productName, productQuantity, unit, productPicture, shap_type, shapBean);
//        Intent mIntent = new Intent();
//        mIntent.putExtra(ConstantUtil.PRODUCTBEAN, productBean);
//        setResult(ConstantUtil.ADD_PRODUCT_INFOMATION, mIntent);

        //        ProductBean productBean = new ProductBean(productName, productQuantity, unit, productPicture, shap_type, shapBean);
//        Intent mIntent = new Intent();
//        mIntent.putExtra(ConstantUtil.PRODUCTBEAN, productBean);
//        setResult(ConstantUtil.ADD_PRODUCT_INFOMATION, mIntent);

        Intent mIntent = new Intent();
        mIntent.putExtra(ConstantUtil.PRODUCTBEAN, true);
        setResult(ConstantUtil.EDIT_PRODUCT_INFOMATION, mIntent);

        Toast.makeText(this, "上传成功", Toast.LENGTH_SHORT).show();
        finish();

    }

    private void remove() {
        Intent mIntent = new Intent();
        mIntent.putExtra(ConstantUtil.PRODUCTBEAN, true);
        setResult(ConstantUtil.DELETE_PRODUCT_INFOMATION, mIntent);


        Toast.makeText(this, "删除成功", Toast.LENGTH_SHORT).show();
        finish();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.btn_upload:
                upload();
                break;
            case R.id.btn_remove:
                remove();
                break;

        }
    }
}
